Ccay.Module.define("Ccay.example.ui.igird.base", function(page, $S)
{
	page.ready = function ()
	{
		var gridOption1 = {
			height: 330,
			wrap: true,
			headTip: true,
			percentWidth:true,
			remoteSort: true,
			customSetting: true,
			seqHeader:"NO.",			
			seqWidth:"5%",	
		    columns: [
		 		{field: 'name', width: "10%", customHeader: "<div><a class='ccay-icon admin'></a>"+ $i18n('ccay.common.label.name').encode() + "</div>"},
		 		{field: 'sex', width: "8%", header: "Sex", type: 'bool'},
		 		{field: 'age', width: "8%", header: "Age", cssName: "center"},
		 		{field: 'birthday', width: "12%", header: "Birthday", type: 'date'},
		 		{field: 'tuition', width: "15%", header: "Tuition", type: 'rate', format: {htmlView: true, section: [20, 40, 80]}},
		 		{field: 'mail', width: "20%", header: "Mail"},
		 		{field: 'blog', width: "23%", header: "sBlog"}
		    ],
			ajax: {
			   	url: 'services/ccay/demo/student/list/page/${pageSize}/${curPage}/${orderBy}'
			}
		};
		
		var gridOption2 = {
			height: 330,
			allowFreezen: true,
		    columns: [
		    	{field: 'name', width: 90, header: "ccay.common.label.name"},
		    	{field: 'birthday', width: 90, header: "Birthday", type: 'date', freezeable: true},
		 		{field: 'sex', width: 70, header: "Sex", type: 'bool', sortable: false},
		 		{field: 'age', width: 70, header: "Age", cssName: "center", sort: 'desc', resizable: false},
		 		{field: 'tuition', width: 170, header: "Tuition", type: 'rate', format: {htmlView: true, section: [20, 40, 80]}},
		 		{field: 'mail', width: 170, header: "Mail(有权限才能看到我哦！)", showTip: true, permission: "Service$HtmlArea$read"},
		 		{field: 'blog', width: 170, header: "Blog", content: "<a href='${blog}'>${blog}</a>"}
		    ],
			ajax:{
			   	url: 'services/ccay/demo/student/list/page/${pageSize}/${curPage}/${orderBy}'
			}
		};
		
		var gridOption3 = {
			height: 330,
			wrap: true,
			showPager: false,
			allowFreezen: true,
		    columns: [
		    	{columnType:'select', multi:false},
		 		{field: 'name', width:70, header: "ccay.common.label.name"},
		 		{field: 'birthday', width:100, header: "Birthday", type: 'date'},
		 		{field: 'blog', width: 170, header: "Blog"}
		    ],
			ajax:{
			   	url: 'services/ccay/demo/student/list/page/10/1/${orderBy}'
			}
		};
		
		var gridOption4 = {
			height: 330,
			wrap: true,
			showPager: false,
			allowFreezen: true,
		    columns: [
		    	{columnType:'select', multi:true, freezeable: true},
		 		{field: 'name', width:70, header: "ccay.common.label.name"},
		 		{field: 'birthday', width:100, header: "Birthday", type: 'date'},
		 		{field: 'blog', width: 170, header: "Blog"}
		    ],
			ajax:{
			   	url: 'services/ccay/demo/student/list/page/10/1/${orderBy}'
			}
		};
		
		var gridOption31 = {
			clickRow2Check:true,
			height: 330,
			wrap: true,
			showPager: false,
			allowFreezen: true,
			editMode: true,
			//onCellClick:function(){Ccay.UI.topBox("该提示是该grid指定了onCellClick事件")},
		    columns: [
		    	{columnType:'select', multi:false},
		 		{field: 'name', width:70, header: "Name（可编辑）"},
		 		{field: 'birthday', width:100, header: "Birthday（可编辑）", type: 'date'},
		 		{field: 'blog', width: 170, header: "Blog（不可编辑）", editable:false}
		    ],
			ajax:{
			   	url: 'services/ccay/demo/student/list/page/10/1/${orderBy}'
			}
		};
		
		var gridOption41 = {
			clickRow2Check:true,
			height: 330,
			wrap: true,
			showPager: false,
			allowFreezen: true,
			editMode: true,
		    columns: [
		    	{columnType:'select', multi:true, freezeable: true},
		 		{field: 'name', width:70, header: "Name（可编辑）"},
		 		{field: 'birthday', width:100, header: "Birthday（可编辑）", type: 'date'},
		 		{field: 'blog', width: 170, header: "Blog（不可编辑）", editable:false}
		    ],
			ajax:{
			   	url: 'services/ccay/demo/student/list/page/10/1/${orderBy}'
			}
		};
		
		var gridOption6 = {
				height: 332,
				editMode:true,
				showPager: true,
				showSeq: true,
				serialSeq: true,
				showOverflow: true,
			 	columns: [
				 {field: 'name', width: 100, customHeader: "<a class='ccay-icon admin'></a>"+ $i18n('ccay.common.label.name'),showTip:true},
				 {field: 'sex', width: 100, header: "Sex", type: 'bool'},
				 {field: 'age', width: 100, header: "Age", cssName: "center"},
				 {field: 'birthday', width: 100, header: "Birthday", type: 'date'},
				 {field: 'tuition', width: 100, header: "Tuition", type: 'rate', format: {htmlView: true, section: [20, 40, 80]}},
				 {field: 'mail', width: 100, header: "Mail"},
				 {field: 'blog', width: 100, header: "sBlog",showTip:true}
			 	],
				ajax:{
				   	url: 'services/ccay/demo/student/list/page/${pageSize}/${curPage}/${orderBy}'
				}
			};
		
		var gridOption7 = {
				height: 332,
				editMode:true,
				showPager: true,
				showSeq: true,
				serialSeq: true,
				totalText: "合计",
			 	columns: [
				 {field: 'name', width: 100, customHeader: "<a class='ccay-icon admin'></a>"+ $i18n('ccay.common.label.name'),totalCount:true},
				 {field: 'sex', width: 100, header: "Sex", type: 'bool'},
				 {field: 'age', width: 100, header: "Age", cssName: "center",totalCount:true},
				 {field: 'birthday', width: 100, header: "Birthday", type: 'date'},
				 {field: 'tuition', width: 100, header: "Tuition", type: 'rate', format: {htmlView: true, section: [20, 40, 80]}},
				 {field: 'mail', width: 100, header: "Mail"},
				 {field: 'blog', width: 100, header: "sBlog",showTip:true}
			 	],
				ajax:{
				   	url: 'services/ccay/demo/student/list/page/${pageSize}/${curPage}/${orderBy}',
				   	ui:"#iStudent7"
				}
			};
		
		var datas3 = [
			{id: 1, name: '1', age:22, pid: null},
			{id: 2, name: '1-1', age:22, pid: 1},
			{id: 12, name: '1-1-1', age:22, pid: 2},
			{id: 13, name: '1-1-2', age:22, pid: 2},
			{id: 14, name: '1-1-2-1', age:22, pid: 13},
            {id: 3, name: '1-2', age:22, pid: 1},
            {id: 4, name: '1-3', age:22, pid: 1},
            {id: 5, name: '2', age:22, pid: null},
            {id: 6, name: '2-1', age:22, pid: 5},
            {id: 8, name: '2-1-1', age:22, pid: 6},
            {id: 19, name: '2-1-1-1', age:22, pid: 8},
            {id: 9, name: '2-1-2', age:22, pid: 6},
            {id: 20, name: '2-1-2-1', age:22, pid: 9},
            {id: 7, name: '2-2', age:22, pid: 5},
            {id: 17, name: '2-2-1', age:22, pid: 7},
            {id: 18, name: '2-2-2', age:22, pid: 7},
            {id: 10, name: '3', age:22, pid: null},
            {id: 15, name: '3-1', age:22, pid: 10},
            {id: 16, name: '3-2', age:22, pid: 10},
            {id: 11, name: '4', age:22, pid: 111}
		];
		
		var datas4 =[
			{id: 1, name: '1', age:22, pid: null},
			{id: 2, name: '1-1', age:22, pid: 1},
			{id: 12, name: '1-1-1', age:22, pid: 2},
			{id: 13, name: '1-1-2', age:22, pid: 2},
			{id: 14, name: '1-1-2-1', age:22, pid: 13},
            {id: 3, name: '1-2', age:22, pid: 1},
            {id: 4, name: '1-3', age:22, pid: 1},
            {id: 5, name: '2', age:22, pid: null},
            {id: 6, name: '2-1', age:22, pid: 5},
            {id: 8, name: '2-1-1', age:22, pid: 6},
            {id: 19, name: '2-1-1-1', age:22, pid: 8},
            {id: 9, name: '2-1-2', age:22, pid: 6},
            {id: 20, name: '2-1-2-1', age:22, pid: 9},
            {id: 7, name: '2-2', age:22, pid: 5},
            {id: 17, name: '2-2-1', age:22, pid: 7},
            {id: 18, name: '2-2-2', age:22, pid: 7},
            {id: 10, name: '3', age:22, pid: null},
            {id: 15, name: '3-1', age:22, pid: 10},
            {id: 16, name: '3-2', age:22, pid: 10},
            {id: 11, name: '4', age:22, pid: 111}
		];
	    
		var gridOption311 = {
			clickRow2Check:true,
			editMode:true,
			showPager: false,
			rowRender: "tree",
			rowRenderOp: {
				parent: "pid",
				field: 'id',
				showField: 'name',
				select: 'single',
				onlyExpandDeep: 1,
				sortData: true
			},
	        columns: [
		        {width: '100px', field: 'name', header: 'name'},
		        {width: '100px', field: 'age', header: 'age(不可编辑)', editable:false},
		        {width: '100px', field: 'id', header: 'id', type: 'integer'},
		        {width: '100px', field: 'pid', header: 'parentId'}
	        ]
	    };
	    
	    var gridOption411 = {
	    	clickRow2Check:true,
			editMode:true,
			showPager: false,
			rowRender: "tree",
			rowRenderOp: {
				parent: "pid",
				field: 'id',
				showField: 'name',
				select: 'multi',
				onlyExpandDeep: 1,
				sortData: true
			},
	        columns: [
		        {width: '100px', field: 'name', header: 'name'},
		        {width: '100px', field: 'age', header: 'age(不可编辑)', editable:false},
		        {width: '100px', field: 'id', header: 'id', type: 'integer'},
		        {width: '100px', field: 'pid', header: 'parentId'}
	        ]
	    };
		
		var gridOption5 = {
			height: 330,
			wrap: true,
			wrapHead: false,
			customHead: '#customHead', 
			colsort : false,
			allowFreezen: true,
		    columns: [
		    	{columnType:'select', multi:true},
		 		{field: 'name', width:90, header: "ccay.common.label.name", freezeable:true},
		 		{field: 'sex', width:70, header: "sSex", type: 'bool', format: {isIcon: true}},
		 		{field: 'age', width:70, header: "sAge", type: 'integer'},
		 		{field: 'birthday', width:110, header: "sBirthday", type: 'date'},
		 		{field: 'mail', width:130, header: "sMail"},
		 		{field: 'blog', width:200, header: "sBlog"},
		 		{field: 'lastUpdateDate', width:130, header: "ccay.common.label.lastUpdatedDate", type: 'datetime'}
		    ],
			ajax:{
			   	url: 'services/ccay/demo/student/list/page/${pageSize}/${curPage}/${orderBy}'
			   	
			}
		};
		
		$S("#baseFunctionDemo").ccayTab();
		
		//点击tab头后，才加载数据，只第一次生效
		$S("li[tabid='tab2']").one("click", function () {
			$S("#iStudent1").igrid(gridOption1);
		});
		
		$S("li[tabid='tab3']").one("click", function () {
			$S("#iStudent2").igrid(gridOption2);
		});
		
		$S("li[tabid='tab4']").one("click", function () {
			$S("#iStudent3").igrid(gridOption3);
			$S("#iStudent4").igrid(gridOption4);
			$S("#iStudent31").igrid(gridOption31);
			$S("#iStudent41").igrid(gridOption41);
			$S("#iStudent311").igrid(gridOption311,datas3);
			$S("#iStudent411").igrid(gridOption411,datas4);
		});
		
		$S("li[tabid='tab5']").one("click", function () {
			$S("#iStudent5").igrid(gridOption5);
		});
		
		$S("li[tabid='tab10']").one("click", function () {
			$S("#iStudent6").igrid(gridOption6);
		});
		
		$S("li[tabid='tab11']").one("click", function () {
			$S("#iStudent7").igrid(gridOption7);
		});
	};
	
	page.operateTest = function(value){
		alert(Ccay.DataHelper.toJsonStr(value));
	};
	
	page.openDemo = function(tabId){
		$S("#baseFunctionDemo").getCcayTabManager().selectItem(tabId);
		$S("li[tabid='" + tabId + "']").click();
	};
	
});